//
//  ConnectModel.m
//  UI 17 _网络图片获取
//
//  Created by dllo on 15/5/7.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ConnectModel.h"

@implementation ConnectModel

+ (void)connectWithStr:(NSString *)str delegate:(id<ConnectionModelDelegate>)delegate
{
    ConnectModel *model = [[ConnectModel alloc] init];
    model.delegate = delegate;
    [model startConnection:str];
}

- (void)startConnection:(NSString *)str
{
    NSString *website = str;
    NSURL *url = [NSURL URLWithString:website];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    
    [request setHTTPMethod:@"GET"];
    
    [NSURLConnection connectionWithRequest:request delegate:self];
    
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    
    
    self.receiveData = [NSMutableData data];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    
    [self.receiveData appendData:data];
    
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [self.delegate connectFinished:self.receiveData];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    
}






@end
